package day11.console.impl;

import day11.console.ConsoleCommand;
import day11.packet.request.QuitGroupRequestPacket;
import day11.util.IDUtil;
import io.netty.channel.Channel;

import java.util.Scanner;

/**
 * @author chenshijie
 * @date 2024/1/2 15:25
 */

public class QuitGroupConsoleCommand implements ConsoleCommand {
    @Override
    public void exec(Scanner sc, Channel channel) {
        System.out.println("输入要退出的群号id");
        String groupId = sc.nextLine();
        if (groupId == null || !IDUtil.isNumeric(groupId)) {
            System.err.println("格式错误");
        } else {
            System.out.println("退出中");
            QuitGroupRequestPacket quitGroupRequestPacket = new QuitGroupRequestPacket();
            quitGroupRequestPacket.setGroupId(Integer.parseInt(groupId));
            channel.writeAndFlush(quitGroupRequestPacket);
        }

    }
}
